package forms;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import beans.Instituicao;



@SuppressWarnings("serial")
public class CadastroInstituicaoForm extends ActionForm {
	
	private Instituicao instituicao = new Instituicao();
	
	
	
	public Instituicao getInstituicao() {
		return instituicao;
	}

	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.instituicao = new Instituicao();
	}
	
	private boolean isStringVazia(String valor){
		return valor == null || valor.trim().length() == 0;
	}
	
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
		
		ActionErrors errors = new ActionErrors();
		
		if (isStringVazia(instituicao.getMunicipio())){
			errors.add("municipio",	new ActionMessage("erro.municipioVazio"));
		} 
		
		if (isStringVazia(instituicao.getResponsavel())){
			errors.add("responsavel",	new ActionMessage("erro.responsavelVazio"));
		}
		
		if (isStringVazia(instituicao.getCargoResponsavel())){
			errors.add("cargoResponsavel",	new ActionMessage("erro.cargoResponsavelVazio"));
		}
		
		if (isStringVazia(instituicao.getTratamentoResponsavel())){
			errors.add("tratamentoResponsavel",	new ActionMessage("erro.tratamentoResponsavelVazio"));
		}
		
		if (isStringVazia(instituicao.getEndereco())){
			errors.add("endereco",	new ActionMessage("erro.enderecoVazio"));
		}
		
		if (isStringVazia(instituicao.getTelefone())){
			errors.add("telefone",	new ActionMessage("erro.telefoneVazio"));
		}
		
		if (isStringVazia(instituicao.getFax())){
			errors.add("fax",	new ActionMessage("erro.faxVazio"));
		} 
		
		return errors;
	}
	
}
